package com.lovo.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Encryptor {

    public static String encrypt(String input) throws NoSuchAlgorithmException {
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(input.getBytes());
        byte[] digest = md.digest();
        StringBuffer sb = new StringBuffer();
        for (byte b : digest) {
            sb.append(String.format("%02x", b & 0xff));
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        try {
            String input = "Hello World";
            String encrypted = encrypt(input);
            System.out.println("Input: " + input);
            System.out.println("MD5 Hash: " + encrypted);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
    }
}

